<?php

class Admin_ToolsController extends Zend_Controller_Action
{

    public function init()
    {
        /* Initialize action controller here */
    	$this->view->headScript()->appendFile($this->view->baseUrl().'/js/jquery-1.8.1.min.js');
    }

    public function indexAction()
    {
        // action body
    }

    public function sitemapAction()
    {
        // action body
		echo realpath(APPLICATION_PATH . '/../');
		$base_path=realpath(APPLICATION_PATH . '/../');
		$sitemap_name="/sitemap.xml";
		echo $base_path.$sitemap_name;
		$xml = '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
		$xml .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . "\n";
		$db_article=new Application_Model_DbTable_Article();
		$resA=$db_article->fetchAll();
		foreach ($resA as $article){
			$xml .= '<url>' . "\n";
			$xml .= "<loc>http://www.taoxiuyu.cn/wenzhang/".$article['article_url_spell']."-aid".$article['article_id'].".html</loc>\n";
			$xml .= "<lastmod>".date('Y-m-d',strtotime($article['article_create_date']))."</lastmod>\n";
			$xml .= "<changefreq>monthly</changefreq>\n";
			$xml .= "<priority>0.4</priority>\n";
			$xml .= '</url>' . "\n";
		}
		
		$db_taobaoitems=new Application_Model_DbTable_TaobaoItems();
		$res=$db_taobaoitems->fetchAll();
		foreach ($res as $item){
			$xml .= '<url>' . "\n";
			$xml .= "<loc>http://www.taoxiuyu.cn/shangpin/".$item['item_url_spell']."-pid".$item['num_iid'].".html</loc>\n";
			$xml .= "<lastmod>".date('Y-m-d',strtotime($item['update_time']))."</lastmod>\n";
			$xml .= "<changefreq>monthly</changefreq>\n";
			$xml .= "<priority>0.4</priority>\n";
			$xml .= '</url>' . "\n";
		}
		$xml .= '</urlset>' . "\n";
		$fp = fopen($base_path.$sitemap_name,'wb');
    	fwrite($fp, $xml);
    	fclose($fp);
		
    }

}



